from pydantic import BaseModel
from typing import Generic, TypeVar, Optional

T = TypeVar('T')


class BaseResponse(BaseModel, Generic[T]):
    code: int = 0
    message: str = "success"
    data: Optional[T] = None

    @classmethod
    def success(cls, data: T = None):
        return cls(code=0, message="success", data=data)

    @classmethod
    def error(cls, code: int, message: str):
        return cls(code=code, message=message, data=None)
